package com.example.t470p.facechecktickets.facesdk;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Build;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import cn.face.FaceService;
import cn.face.localsdkdemo.ConStant;
import cn.face.localsdkdemo.sdkproc.LocalSDK;
import cn.face.localsdkdemo.util.FileUtil;
import cn.face.localsdkdemo.util.PreferencesUtils;

/**
 * Created by zhaodianbo on 2018-1-26.
 */
public class FaceAuthAsync extends AsyncTask<Void,Void,Integer>{

    Context mContext;
    OnFinish onFinish;
    private ProgressDialog dialog = null;
    IFaceSDK iFaceSDK;
    public FaceAuthAsync(Context mContext,IFaceSDK iFaceSDK) {
        this.mContext = mContext;
        this.iFaceSDK=iFaceSDK;
    }
    public FaceAuthAsync setOnfinish(OnFinish onfinish){
        this.onFinish=onfinish;
        return this;
    }
    public interface OnFinish{
        void onDone(boolean initOk, int errCode);
    }

    @Override
    protected void onPreExecute() {
        dialog = ProgressDialog.show(mContext, "", "正在进行人脸授权，请稍等...", true);
        super.onPreExecute();
    }

    @Override
    protected Integer doInBackground(Void... params) {
        return iFaceSDK.init(mContext);
    }

    @Override
    protected void onPostExecute(Integer ret) {
        super.onPostExecute(ret);
        if(ret!=0){
            new AlertDialog.Builder(mContext).setMessage("人脸授权失败:errcode="+ret).show();
        }
        hideProgress();
        if(onFinish!=null){
            onFinish.onDone(ret==0,ret);
        }
    }

    private void hideProgress() {
        if (dialog != null && dialog.isShowing())
            dialog.dismiss();
    }
}
